var mxResources =
{
	resources: {},
	add: function(basename, lan)
	{
		lan = (lan != null) ? lan : mxClient.language;

		if (lan != 'none')
		{
			try
			{
				var req = mxUtils.load(basename + '.properties');

				if (req.isReady())
				{
					mxResources.parse(req.getText());
				}
			}
			catch (e)
			{
			}

			try
			{
				var req = mxUtils.load(basename + '_' + lan + '.properties');

				if (req.isReady())
				{
					mxResources.parse(req.getText());
				}
			}
			catch (e)
			{
			}
		}
	},
	parse: function(text)
	{
		var lines = text.split('\n');

		for (var i = 0; i < lines.length; i++)
		{
			var index = lines[i].indexOf('=');

			if (index > 0)
			{
				var key = lines[i].substring(0, index);
				var idx = lines[i].length;

				if (lines[i].charCodeAt(idx - 1) == 13)
				{
					idx--;
				}
				var value = lines[i].substring(index + 1, idx);
				mxResources.resources[key] = unescape(value);
			}
		}
	},
	get: function(key, params, defaultValue)
	{
		var value = mxResources.resources[key];

		if (value == null)
		{
			value = defaultValue;
		}

		if (value != null && params != null)
		{
			var result = [];
			var index = null;

			for (var i = 0; i < value.length; i++)
			{
				var c = value.charAt(i);

				if (c == '{')
				{
					index = '';
				}
				else if (index != null && c == '}')
				{
					index = parseInt(index) - 1;

					if (index >= 0 && index < params.length)
					{
						result.push(params[index]);
					}
					index = null;
				}
				else if (index != null)
				{
					index += c;
				}
				else
				{
					result.push(c);
				}
			}
			value = result.join('');
		}
		return value;
	}
};